<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增差旅报销单')" />
    <th:block th:include="include :: datetimepicker-css" />
    <style type="text/css">
        table label.error{position: inherit;}select + label.error{z-index:1;right:40px;}
    </style>
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-clbxd-add">
        	<input name="gcProjectid" type="hidden" th:value="${gcProject.id}" >
        	<input type="hidden" id="approvename" name="approvename" th:value="${approvename}" />
        	<input type="hidden" id="owner" name="owner" th:value="${owner}" />
        	<input type="hidden" id="ownerId" name="ownerId" th:value="${ownerId}" />
        	<input name="name" type="hidden" th:value="${gcProject.name}" />
        	<h4 class="form-header h4">基本信息</h4>
            <div class="form-group"> 
            	<label class="col-sm-1 control-label is-required">出差事由：</label>
                <div class="col-sm-2">
                    <input name="chucsy" class="form-control" type="text" autoComplete="off" required>
                </div> 
                <label class="col-sm-1 control-label is-required">核销时间：</label>
                <div class="col-sm-2">
                    <div class="input-group date">
                        <input name="chucsj" class="form-control" placeholder="yyyy-MM-dd" th:value="${chucsj}" type="text" autoComplete="off" required>
                        <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                    </div>
                </div>  
                <label class="col-sm-1 control-label is-required">报销人：</label>
                <div class="col-sm-2">
                    <input name="chucr" class="form-control" type="text" autoComplete="off" readonly="readonly" required th:value="${chucr}">
                </div>
<!--                 <label class="col-sm-1 control-label is-required">费用类型：</label> -->
<!--                 <div class="col-sm-2"> -->
<!--                 	<select name="type" class="form-control" th:with="type=${@dict.getType('fyhx_type')}" required> -->
<!-- 					  <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictLabel}"> -->
<!-- 					  </option> -->
<!-- 					</select> -->
<!--                 </div> -->
<!--             	<label class="col-sm-1 control-label is-required">单据数量：</label> -->
<!--                 <div class="col-sm-1"> -->
<!--                     <input name="djsl" class="form-control" type="text" autoComplete="off" required> -->
<!--                 </div> -->
            	<label class="col-sm-1 control-label is-required">申请部门：</label>
                <div class="col-sm-2">
                    <input name="dept" class="form-control" type="text" th:value="${deptName}" autoComplete="off" readonly="readonly" required>
                    <input name="deptId" th:value="${deptId}" type="hidden">
                </div>
            </div>
            <div class="form-group"> 
            	<label class="col-sm-1 control-label is-required">项目所属：</label>
                <div class="col-sm-2">
                    <select name="authority" class="form-control" required>
						<option th:each="cl:${deptlis}" th:value="${cl.deptId}" th:text="${cl.deptName}"></option>
					</select>
                </div>
                <label class="col-sm-1 control-label is-required">付款单位：</label>
            	<div class="col-sm-2">
            		<select name="ztdw" class="form-control" th:with="type=${@dict.getType('sj_gongs')}" required>
                    	<option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                	</select>
                </div>
            </div>
            <div class="form-group">
            	<label class="col-sm-1 control-label is-required">证明人：</label>
                <div class="col-sm-2">
                	<div class="input-group">
                    	<input id="zmr" name="zmr" class="form-control" type="hidden">
                    	<input id="zmrId" name="zmrId" class="form-control" type="hidden">
                    	<input class="form-control" type="text" onclick="selectlevel1()" id="zmrStr" readonly="true" required>
						<span class="input-group-addon"><i class="fa fa-search"></i></span>
					</div>
                </div>
                <label class="col-sm-1 control-label is-required">会计复核：</label>
                <div class="col-sm-2">
                	<div class="input-group">
                    	<input id="hj" name="hj" class="form-control" type="hidden">
                    	<input id="hjId" name="hjId" class="form-control" type="hidden">
                    	<input class="form-control" type="text" onclick="selectlevel2()" id="hjStr" readonly="true" required>
						<span class="input-group-addon"><i class="fa fa-search"></i></span>
					</div>
                </div>
            	<label class="col-sm-1 control-label is-required">副总审批1：</label>
                <div class="col-sm-2">
                	<div class="input-group">
                    	<input id="fzjl1" name="fzjl1" class="form-control" type="hidden">
                    	<input id="fzjl1Id" name="fzjl1Id" class="form-control" type="hidden">
                    	<input class="form-control" type="text" onclick="selectlevel3()" id="fzjl1Str" readonly="true" required>
						<span class="input-group-addon"><i class="fa fa-search"></i></span>
					</div>
                </div>
                <label class="col-sm-1 control-label is-required">副总审批2：</label>
                <div class="col-sm-2">
                	<div class="input-group">
                    	<input id="fzjl2" name="fzjl2" class="form-control" type="hidden">
                    	<input id="fzjl2Id" name="fzjl2Id" class="form-control" type="hidden">
                    	<input class="form-control" type="text" onclick="selectlevel4()" id="fzjl2Str" readonly="true" required>
						<span class="input-group-addon"><i class="fa fa-search"></i></span>
					</div>
                </div>
            </div>
            <div class="form-group">
            	<label class="col-sm-1 control-label is-required">总经理：</label>
                <div class="col-sm-2">
                	<div class="input-group">
                    	<input id="zjl" name="zjl" class="form-control" type="hidden">
                    	<input id="zjlId" name="zjlId" class="form-control" type="hidden">
                    	<input class="form-control" type="text" onclick="selectlevel5()" id="zjlStr" readonly="true" required>
						<span class="input-group-addon"><i class="fa fa-search"></i></span>
					</div>
                </div>
                <label class="col-sm-1 control-label is-required">出纳：</label>
                <div class="col-sm-2">
                	<div class="input-group">
                    	<input id="cn" name="cn" class="form-control" type="hidden">
                    	<input id="cnId" name="cnId" class="form-control" type="hidden">
                    	<input class="form-control" type="text" onclick="selectlevel6()" id="cnStr" readonly="true" required>
						<span class="input-group-addon"><i class="fa fa-search"></i></span>
					</div>
                </div>
            </div>
            <h4 class="form-header h4">表单项</h4>
            <div class="row">
                <div class="col-sm-12">
                    <button type="button" class="btn btn-white btn-sm" onclick="addRow()"><i class="fa fa-plus"> 增加</i></button>
                    <div class="col-sm-12 select-table table-striped">
					    <table id="bootstrap-table"></table>
					</div>
                </div>
            </div>
        </form>
    </div>
    <div class="row">
        <div class="col-sm-offset-5 col-sm-10">
            <button type="button" class="btn btn-sm btn-primary" onclick="submitHandler()"><i class="fa fa-check"></i>保 存</button>&nbsp;
            <button type="button" class="btn btn-sm btn-danger" onclick="closeItem()"><i class="fa fa-reply-all"></i>关 闭 </button>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: datetimepicker-js" />
    <script th:src="@{/js/jquery.tmpl.js}"></script>
    <script th:inline="javascript">
        var prefix = ctx + "gcgl/clbxd"
        $("#form-clbxd-add").validate({
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
                $.operate.saveTab(prefix + "/add", $('#form-clbxd-add').serialize());
            }
        }

        $("input[name='chucsj']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });

        $("input[name='bxrAt']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });

        $(function() {
	    	// 初始化数据, 可以由后台传过来
		    var options = {
                pagination: false,
		        showSearch: false,
                showRefresh: false,
                showToggle: false,
                showColumns: false,
                sidePagination: "client",
		        columns: [
		        {
		        	field: 'index',
		        	align: 'center',
		        	title: "序号",
                    formatter: function (value, row, index) {
                    	var columnIndex = $.common.sprintf("<input type='hidden' name='index' value='%s'>", $.table.serialNumber(index));
                    	var columnId = $.common.sprintf("<input type='hidden' name='item[%s].xuh' value='%s'>", index, row.id);
                    	return columnIndex + $.table.serialNumber(index) + columnId;
                    }
                },
		        {
		            field: 'cfrq',
		            align: 'center',
		            title: '出发日期',
		            formatter: function(value, row, index) {
		            	var html = $.common.sprintf("<div class='input-group date'><input style='width:100px' required name='item[%s].cfrq' value='%s' class='form-control itemcfrq' placeholder='yyyy-MM-dd' type='text' autoComplete='off'><span class='input-group-addon'><i class='fa fa-calendar'></i></span></div>", index, value);
		        		return html;
                    }
		        },
		        {
		            field: 'cfdd',
		            align: 'center',
		            title: '出发地点',
		            formatter: function(value, row, index) {
		            	var html = $.common.sprintf("<input style='width:100px' class='form-control itemcfdd' type='text' autoComplete='off' name='item[%s].cfdd' value='%s'>", index, value);
		        		return html;
                    }
		        },
		        {
		            field: 'ddrq',
		            align: 'center',
		            title: '到达日期',
		            formatter: function(value, row, index) {
		            	var html = $.common.sprintf("<div class='input-group date'><input style='width:100px' required name='item[%s].ddrq' value='%s' class='form-control itemddrq' placeholder='yyyy-MM-dd' type='text' autoComplete='off'><span class='input-group-addon'><i class='fa fa-calendar'></i></span></div>", index, value);
		        		return html;
                    }
		        },
		        {
		            field: 'dddd',
		            align: 'center',
		            title: '到达地点',
		            formatter: function(value, row, index) {
		            	var html = $.common.sprintf("<input style='width:100px' class='form-control itemdddd' type='text' autoComplete='off' name='item[%s].dddd' value='%s'>", index, value);
		        		return html;
                    }
		        },
		        {
		            field: 'rs',
		            align: 'center',
		            title: '人数',
		            formatter: function(value, row, index) {
		            	var html = $.common.sprintf("<input style='width:50px' class='form-control itemrs' type='text' autoComplete='off' name='item[%s].rs' value='%s'>", index, value);
		        		return html;
                    }
		        },
		        {
		            field: 'jtfs',
		            align: 'center',
		            title: '交通方式',
		            formatter: function(value, row, index) {
		        		var data = [{ index: index, type: value }];
		                return $("#itemJtfs").tmpl(data).html();
                    }
		        },
		        {
		            field: 'jtje',
		            align: 'center',
		            title: '交通金额',
		            formatter: function(value, row, index) {
		            	var html = $.common.sprintf("<input style='width:100px' class='form-control itemjtje' type='text' autoComplete='off' name='item[%s].jtje' value='%s'>", index, value);
		        		return html;
                    }
		        },
		        {
		            field: 'ts',
		            align: 'center',
		            title: '天数',
		            formatter: function(value, row, index) {
		            	var html = $.common.sprintf("<input style='width:50px' class='form-control itemts' type='text' autoComplete='off' name='item[%s].ts' value='%s'>", index, value);
		        		return html;
                    }
		        },
		        {
		            field: 'ccbzbz',
		            align: 'center',
		            title: '出差标准',
		            formatter: function(value, row, index) {
		            	var html = $.common.sprintf("<input style='width:100px' class='form-control itemccbzbz' type='text' autoComplete='off' name='item[%s].ccbzbz' value='%s'>", index, value);
		        		return html;
                    }
		        },
		        {
		            field: 'ccbzje',
		            align: 'center',
		            title: '补助金额',
		            formatter: function(value, row, index) {
		            	var html = $.common.sprintf("<input style='width:100px' class='form-control itemccbzje' type='text' autoComplete='off' name='item[%s].ccbzje' value='%s'>", index, value);
		        		return html;
                    }
		        },
		        {
		            field: 'ccbzzs',
		            align: 'center',
		            title: '住宿费用',
		            formatter: function(value, row, index) {
		            	var html = $.common.sprintf("<input style='width:100px' class='form-control itemccbzzs' type='text' autoComplete='off' name='item[%s].ccbzzs' value='%s'>", index, value);
		        		return html;
                    }
		        },
		        {
		            field: 'qtfyjesnjt',
		            align: 'center',
		            title: '燃油交通费',
		            formatter: function(value, row, index) {
		            	var html = $.common.sprintf("<input style='width:100px' class='form-control itemqtfyjesnjt' type='text' autoComplete='off' name='item[%s].qtfyjesnjt' value='%s'>", index, value);
		        		return html;
                    }
		        },
		        {
		            field: 'qtfyjejery',
		            align: 'center',
		            title: '其它费用',
		            formatter: function(value, row, index) {
		            	var html = $.common.sprintf("<input style='width:100px' class='form-control itemqtfyjejery' type='text' autoComplete='off' name='item[%s].qtfyjejery' value='%s'>", index, value);
		        		return html;
                    }
		        },
// 		        {
// 		            field: 'qtfyjetcf',
// 		            align: 'center',
// 		            title: '其它费用金额停车费',
// 		            formatter: function(value, row, index) {
// 		            	var html = $.common.sprintf("<input style='width:100px' class='form-control itemqtfyjetcf' type='text' autoComplete='off' name='item[%s].qtfyjetcf' value='%s'>", index, value);
// 		        		return html;
//                     }
// 		        },
		        {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                    	var value = $.common.isNotEmpty(row.index) ? row.index : $.table.serialNumber(index);
                        return '<a class="btn btn-danger btn-xs" href="javascript:void(0)" onclick="sub.delColumnByIndex(\'' + value + '\')"><i class="fa fa-remove"></i>删除</a>';
                    }
                }]
		    };
		    $.table.init(options);
		});
        
        $.validator.addMethod("itemcfrq", function(value, element) {
            return !this.optional(element);
        }, "出发日期必填。");
        $.validator.addMethod("itemcfdd", function(value, element) {
            return !this.optional(element);
        }, "出发地点必填。");
        $.validator.addMethod("itemddrq", function(value, element) {
            return !this.optional(element);
        }, "到达日期必填。");
        $.validator.addMethod("itemdddd", function(value, element) {
            return !this.optional(element);
        }, "到达地点必填。");
        $.validator.addMethod("itemrs", function(value, element) {
            return !this.optional(element);
        }, "人数必填。");
        $.validator.addMethod("itemjtfs", function(value, element) {
            return !this.optional(element);
        }, "交通方式必填。");
        $.validator.addMethod("itemjtje", function(value, element) {
            return !this.optional(element) && (value <= 100000 && value >= 0);
        }, "交通金额长度区间0-100000。");
        $.validator.addMethod("itemts", function(value, element) {
            return !this.optional(element);
        }, "天数必填。");
        
        /**
        $.validator.addMethod("itemccbzbz", function(value, element) {
            return !this.optional(element);
        }, "标准必填。");
        $.validator.addMethod("itemccbzje", function(value, element) {
            return !this.optional(element) && (value <= 100000 && value >= 1);
        }, "金额长度区间1-100000。");
        $.validator.addMethod("itemccbzzs", function(value, element) {
            return !this.optional(element);
        }, "住宿必填。");
        
        $.validator.addMethod("itemqtfyjesnjt", function(value, element) {
            return !this.optional(element) && (value <= 100000 && value >= 1);
        }, "市内交通长度区间1-100000。");
        $.validator.addMethod("itemqtfyjejery", function(value, element) {
            return !this.optional(element) && (value <= 100000 && value >= 1);
        }, "燃油长度区间1-100000。");
        $.validator.addMethod("itemqtfyjetcf", function(value, element) {
            return !this.optional(element) && (value <= 100000 && value >= 1);
        }, "停车费长度区间1-100000。");
        **/
        
        function addRow() {
        	
        	var count = $("#" + table.options.id).bootstrapTable('getData').length;
        	
        	var row = {
                index: $.table.serialNumber(count),
                cfrq: "",
                cfdd: "",
                ddrq: "",
                dddd: "",
                rs: "",
                jtfs: "",
                jtje: "",
                ts: "",
                ccbzbz: "",
                ccbzje: "",
                ccbzzs: "",
                qtfyjesnjt: "",
                qtfyjejery: "",
                qtfyjetcf: ""
            }
        	sub.addColumn(row);
        	
        	for(var i=0;i<=count;i++){
        		$("input[name='item["+i+"].cfrq']").datetimepicker({
                    format: "yyyy-mm-dd",
                    minView: "month",
                    autoclose: true
                });
            	$("input[name='item["+i+"].ddrq']").datetimepicker({
                    format: "yyyy-mm-dd",
                    minView: "month",
                    autoclose: true
                });
        	}
        	
        }
        
      //-----------------------
        //选择用户level1
		function selectlevel1() {
			var options = {
		       title: '选择用户',
		       url: "/sj/config/invokeUser",
		       width: '1000',
		       height: '670',
		       callBack: doSubmitlevel1User
		    };
		    $.modal.openOptions(options);
		}
	 	
		function doSubmitlevel1User(index, layero){
            var rows = layero.find("iframe")[0].contentWindow.getSelections();
            if (rows.length == 0) {
                $.modal.alertWarning("请选择一条记录！");
                return;
            }
            
            if (rows.length > 1) {
                $.modal.alertWarning("请勿选择多条记录！");
                return;
            }
            
            $("#zmrId").val(rows[0].userId);
            $("#zmr").val(rows[0].userName);
            $("#zmrStr").val(rows[0].userName);
            $.modal.closeAll();
        }
		
		//选择用户level2
		function selectlevel2() {
			var options = {
		       title: '选择用户',
		       url: "/sj/config/invokeUser",
		       width: '1000',
		       height: '670',
		       callBack: doSubmitlevel2User
		    };
		    $.modal.openOptions(options);
		}
	 	
		function doSubmitlevel2User(index, layero){
            var rows = layero.find("iframe")[0].contentWindow.getSelections();
            if (rows.length == 0) {
                $.modal.alertWarning("请选择一条记录！");
                return;
            }
            
            if (rows.length > 1) {
                $.modal.alertWarning("请勿选择多条记录！");
                return;
            }
            
            $("#hjId").val(rows[0].userId);
            $("#hj").val(rows[0].userName);
            $("#hjStr").val(rows[0].userName);
            $.modal.closeAll();
        }
		
		//选择用户level3
		function selectlevel3() {
			var options = {
		       title: '选择用户',
		       url: "/sj/config/invokeUser",
		       width: '1000',
		       height: '670',
		       callBack: doSubmitlevel3User
		    };
		    $.modal.openOptions(options);
		}
	 	
		function doSubmitlevel3User(index, layero){
            var rows = layero.find("iframe")[0].contentWindow.getSelections();
            if (rows.length == 0) {
                $.modal.alertWarning("请选择一条记录！");
                return;
            }
            
            if (rows.length > 1) {
                $.modal.alertWarning("请勿选择多条记录！");
                return;
            }
            
            $("#fzjl1Id").val(rows[0].userId);
            $("#fzjl1").val(rows[0].userName);
            $("#fzjl1Str").val(rows[0].userName);
            $.modal.closeAll();
        }
		
		//选择用户level4
		function selectlevel4() {
			var options = {
		       title: '选择用户',
		       url: "/sj/config/invokeUser",
		       width: '1000',
		       height: '670',
		       callBack: doSubmitlevel4User
		    };
		    $.modal.openOptions(options);
		}
	 	
		function doSubmitlevel4User(index, layero){
            var rows = layero.find("iframe")[0].contentWindow.getSelections();
            if (rows.length == 0) {
                $.modal.alertWarning("请选择一条记录！");
                return;
            }
            
            if (rows.length > 1) {
                $.modal.alertWarning("请勿选择多条记录！");
                return;
            }
            
            $("#fzjl2Id").val(rows[0].userId);
            $("#fzjl2").val(rows[0].userName);
            $("#fzjl2Str").val(rows[0].userName);
            $.modal.closeAll();
        }
		
		//选择用户level5
		function selectlevel5() {
			var options = {
		       title: '选择用户',
		       url: "/sj/config/invokeUser",
		       width: '1000',
		       height: '670',
		       callBack: doSubmitlevel5User
		    };
		    $.modal.openOptions(options);
		}
	 	
		function doSubmitlevel5User(index, layero){
            var rows = layero.find("iframe")[0].contentWindow.getSelections();
            if (rows.length == 0) {
                $.modal.alertWarning("请选择一条记录！");
                return;
            }
            
            if (rows.length > 1) {
                $.modal.alertWarning("请勿选择多条记录！");
                return;
            }
            
            $("#zjlId").val(rows[0].userId);
            $("#zjl").val(rows[0].userName);
            $("#zjlStr").val(rows[0].userName);
            $.modal.closeAll();
        }
		
		//选择用户level6
		function selectlevel6() {
			var options = {
		       title: '选择用户',
		       url: "/sj/config/invokeUser",
		       width: '1000',
		       height: '670',
		       callBack: doSubmitlevel6User
		    };
		    $.modal.openOptions(options);
		}
	 	
		function doSubmitlevel6User(index, layero){
            var rows = layero.find("iframe")[0].contentWindow.getSelections();
            if (rows.length == 0) {
                $.modal.alertWarning("请选择一条记录！");
                return;
            }
            
            if (rows.length > 1) {
                $.modal.alertWarning("请勿选择多条记录！");
                return;
            }
            
            $("#cnId").val(rows[0].userId);
            $("#cn").val(rows[0].userName);
            $("#cnStr").val(rows[0].userName);
            $.modal.closeAll();
        }
    </script>
</body>
</html>

<!-- 成本类型 -->
<script id="itemJtfs" type="text/x-jquery-tmpl">
<div>
<select class='form-control' name='item[${index}].jtfs' style='width:70px'>
    <option value="火车" {{if type==="火车"}}selected{{/if}}>火车</option>
	<option value="汽车" {{if type==="汽车"}}selected{{/if}}>汽车</option>
	<option value="飞机" {{if type==="飞机"}}selected{{/if}}>飞机</option>
</select>
</div>
</script>